package points

import (
	"context"
	"gitee.com/enjoy_5/sigin-rpc/internal/sever"
	pb "gitee.com/enjoy_5/sigin-rpc/proto/points"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
)

type ServerPoints struct {
	pb.UnimplementedPointsServer
}

func (s *ServerPoints) CreatePoints(ctx context.Context, in *pb.CreatePointsReq) (*pb.CreatePointsResp, error) {
	_, err := sever.CreatePoints(in)

	if err != nil {
		return nil, status.Errorf(codes.Unimplemented, "method CreatePoints not implemented")
	}
	return &pb.CreatePointsResp{}, nil
}
func (s *ServerPoints) GetPoints(ctx context.Context, in *pb.GetPointsReq) (*pb.GetPointsResp, error) {
	stu, err := sever.GetPoints(in)
	if err != nil {
		return nil, status.Errorf(codes.Internal, "internal error: %s", err)
	}
	var point []*pb.Info
	for _, v := range stu {
		point = append(point, &pb.Info{UserId: v.UserId, Username: v.Username, PointsBalance: v.PointsBalance})
	}
	return &pb.GetPointsResp{
		Info: point,
	}, nil

}
func (s *ServerPoints) UpdatePoints(ctx context.Context, in *pb.UpdatePointsReq) (*pb.UpdatePointsResp, error) {
	_, err := sever.UpdatePoints(in)
	if err != nil {
		return nil, status.Errorf(codes.Unimplemented, "method UpdatePoints not implemented")
	}
	return &pb.UpdatePointsResp{}, nil
}
